var e,
  i = require("../../api/utils/logUtil.js"),
  t = require("../../api/utils/base64.js"),
  n = require("../../buildConfig.js").BuildConfig,
  r = "https://turingminipro.sparta.html5.qq.com/captcha/",
  s = [],
  o = 0,
  u = [],
  l = 0;
module.exports = {
  addSensor: function (e) {
    if (null != e) {
      var t = s.length,
        n = e.timestamp;
      if (t <= 0) return (o = n), void s.push(e);
      var r = Math.abs(n - o);
      r <= 1e4 && (i.d("add Sensor", r + ", " + JSON.stringify(e)), s.push(e));
    }
  },
  addTouch: function (e) {
    if (null != e) {
      var t = u.length,
        n = e.timestamp;
      if (t <= 0) return (l = n), void u.push(e);
      var r = Math.abs(n - l);
      r <= 1e4 && (i.d("addTouch", r + ", " + JSON.stringify(e)), u.push(e));
    }
  },
  verify: function (e, t) {
    var n = r.concat("Verify");
    i.d("verify req", n + ", " + JSON.stringify(e)),
      wx.request({
        url: n,
        method: "post",
        data: e,
        success: function (e) {
          null != t && t.onSuccess(e);
        },
        fail: function (e) {
          null != t && t.onFail(e);
        },
      });
  },
  buildVerifyReq: function (e, n, r, o, l) {
    var a = {
      touch_duration: e,
      unisid: t.base64Encode(n),
      verify_offset_x: r,
      frequency: o,
      touch_list: u,
      sensor_list: s,
      extra_val: l,
    };
    return i.d("buildVerifyReq", JSON.stringify(a)), a;
  },
  clearAll: function () {
    (s.length = 0),
      (u.length = 0),
      (o = 0),
      (l = 0),
      i.d("clearAll", JSON.stringify(s));
  },
  getCaptcha: function (t, n, s) {
    var o = r.concat("Get"),
      u = { appid: t, clientInfo: e, extra_val: n };
    i.d("getCaptcha", o + ", " + JSON.stringify(u)),
      wx.request({
        url: o,
        method: "post",
        data: u,
        success: function (e) {
          null != s && s.onSuccess(e);
        },
        fail: function (e) {
          null != s && s.onFail(e);
        },
      });
  },
  buildSensorInfo: function (e, i) {
    return {
      sensorType: e,
      timestamp: new Date().getTime(),
      sensorX: i.x,
      sensorY: i.y,
      sensorZ: i.z,
    };
  },
  buildTouchInfo: function (e, i) {
    return {
      touchType: e,
      timestamp: new Date().getTime(),
      identifier: i.identifier,
      touchX: i.clientX,
      touchY: i.clientY,
      touchForce: i.force,
    };
  },
  buildClientInfo: function (i, t, r, s, o) {
    e = {
      buildno: n.buildNo,
      sdkver: n.sdkVersion,
      lc: n.lc,
      model: i,
      brand: t,
      wx_version: r,
      wx_sdk_version: s,
      system_version: o,
    };
  },
};
